#include "stdafx.h"
#include "wf_layersedit.h"

#include "pf_graphic.h"



WF_LayersEdit::WF_LayersEdit(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Edit Layer", container, graphicView) {}


QAction* WF_LayersEdit::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Edit Layer")
    QAction* action = new QAction(tr("&Edit Layer"), NULL);
    //action->zetStatusTip(tr("Edit Layer"));
	action->setIcon(QIcon(":/ui/layeredit.png"));
    return action;
}

void WF_LayersEdit::trigger() {
    PF_DEBUG->print("PF_ActionLayersEdit::trigger");

    PF_Layer* layer = NULL;

    if (graphic!=NULL) {
        layer =
            PF_DIALOGFACTORY->requestEditLayerDialog(graphic->getLayerList());

        if (layer!=NULL) {
            graphic->editLayer(graphic->getActiveLayer(), *layer);

            // update updateable entities on the layer that has changed
            for (PF_Entity* e=graphic->firstEntity(LX_Define::ResolveNone);
                    e!=NULL;
                    e=graphic->nextEntity(LX_Define::ResolveNone)) {

                PF_Layer* l = e->getLayer();
                if (l!=NULL && l->getName()==layer->getName()) {
                    e->update();
                }
            }
        }
    }
    finish();

	graphicView->redraw(LX_Define::RedrawDrawing); 

}



void WF_LayersEdit::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}

// EOF
